Skip to content

[RFC] Friends#21937

Draft
DanielEScherzer wants to merge 7 commits intophp:masterfrom
DanielEScherzer:friends
Draft

[RFC] Friends#21937
DanielEScherzer wants to merge 7 commits intophp:masterfrom
DanielEScherzer:friends

Conversation

@DanielEScherzer
Copy link
Copy Markdown
Member

No description provided.

<?php

class Foo {
friend Bar;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense also to allow wildcard at the end like friend *; or Subnamespace\* or \DifferentNs\*?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friend * is just making things accessible in all classes, but not outside of classes, which doesn't seem much better than just making things public

namespaces with wildcards feels like a backdoor namespace visibility, which is something being discussed separately on https://wiki.php.net/rfc/namespace_visibility

Copy link
Copy Markdown
Contributor

@mvorisek mvorisek May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant * (not \*) to allow all classes in current namespace.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is potential future scope but should not be included here, and I also think having friend * mean everything in the namespace rather than everything in any namespace would be a bit confusing, so I'm not going to include that in the initial RFC, but thanks for the suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants